package com.sddfp.common.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class TokenUtils {
    public static Long getTokenUserId() {
        HttpServletRequest request= ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String token = request.getHeader("Authorization");
        token = token.replace("Bearer ","");
        JwtTemplate jwtTemplate = new JwtTemplate();
        Number userId = (Number) jwtTemplate.parseToken(token,"userId");
        return userId.longValue();
    }
}
